import { articleControllerFindOne } from "@/app/servers/api/article";
import { userControllerGetUserInfo } from "@/app/servers/api/user";
import { cookies, headers } from "next/headers";
import ModifyArticle from "./modify-article";

export default async function UpdateArticle(req: { params: { id: string } }) {
  const { data: userinfo } = await userControllerGetUserInfo({
    next: {
      headers: headers(),
      cookies: cookies(),
    },
  });
  console.log(req,req.params);
  
  const { data: article } = await articleControllerFindOne(
    {
      id: req?.params?.id,
    },
    {
      next: {
        headers: headers(),
        cookies: cookies(),
      },
    }
  );
  if (article.userId !== userinfo.id) {
    throw "这不是你创建的文章";
  }
  console.log(article);
  
  return <ModifyArticle article={article} />;
}
